package zl.com.gz_2017029e.adapter;

import android.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import zl.com.gz_2017029e.R;

/**
 * Created by Administrator on 2019/1/11 0011.
 */

public class CrossroadsAdapter extends RecyclerView.Adapter<CrossroadsAdapter.ViewHolder>{
    private List<Crossroads> crossroadsList = new ArrayList<>();

    public CrossroadsAdapter(List<Crossroads> crossroadsList) {
        this.crossroadsList = crossroadsList;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        private TextView index,redLight,yellowLight,greenLight;
        private CheckBox operation;
        private Button seting;

        public ViewHolder(View itemView) {
            super(itemView);
            index = (TextView)itemView.findViewById(R.id.crossroads_index_tv);
            redLight = (TextView)itemView.findViewById(R.id.crossroads_red_tv);
            yellowLight = (TextView)itemView.findViewById(R.id.crossroads_yellow_tv);
            greenLight = (TextView)itemView.findViewById(R.id.crossroads_green_tv);
            operation = (CheckBox)itemView.findViewById(R.id.crossroads_operation_cb);
            seting = (Button)itemView.findViewById(R.id.crossroads_set_btn);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.crossroads_item,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        Crossroads crossroads = crossroadsList.get(position);
        holder.index.setText(String.valueOf(crossroads.getCrossroadsId()));
        holder.redLight.setText(String.valueOf(crossroads.getRlight()));
        holder.yellowLight.setText(String.valueOf(crossroads.getYlight()));
        holder.greenLight.setText(String.valueOf(crossroads.getGlight()));
        holder.seting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder rgySetingBuilder = new AlertDialog.Builder(holder.itemView.getContext());
                View view1 = LayoutInflater.from(holder.itemView.getContext()).inflate(R.layout.rgysetingdialog,null);
                rgySetingBuilder.setView(view1);
//                rgySetingBuilder.setTitle("红绿灯设置");
                rgySetingBuilder.setCancelable(true);
//                rgySetingBuilder.setPositiveButton()
                rgySetingBuilder.show();
            }
        });
//        holder.operation.setOnCheckedChangeListener(this);
    }

    @Override
    public int getItemCount() {
        return crossroadsList.size();
    }


}
